

export async function getToken() {
	const token = await uni.getStorageSync('uni_session')
  return token //localStorage.getItem("uni_session")//
}

export function isTimeExpired(timeString) {
	if(timeString==null || timeString==undefined){
		return true;
	}
  // 将给定的时间字符串转换为 Date 对象
  const givenTime = new Date(timeString);

  // 获取当前时间
  const currentTime = new Date();

  // 比较两个时间
  if (givenTime <= currentTime) {
    return false; // 时间已过期
  } else {
    return true; // 时间未过期
  }
}

export function getCurrentDate() {
	const today = new Date();

	const year = today.getFullYear();
	const month = today.getMonth() + 1;
	const day = today.getDate();

	const formattedMonth = month.toString().padStart(2, '0');
	const formattedDay = day.toString().padStart(2, '0');

	return `${year}-${formattedMonth}`;
}

export function countdownDays(targetDateString) {
    // 转换目标日期字符串为Date对象
    const targetDate = new Date(targetDateString);
    // 获取当前日期
    const now = new Date();
    
    // 计算两个日期之间的差异（毫秒）
    const dateDiffMs = now.getTime()-targetDate.getTime();
    
    // 检查是否为有效的时间差
    if (isNaN(dateDiffMs)) {
        console.error('Invalid date provided.');
        return;
    }
    
    // 将毫秒转换为天数
    const dateDiffDays = Math.round(dateDiffMs / (1000 * 60 * 60 * 24));
    
    return dateDiffDays;
}

export function  isJZNull(content){
    if (content == undefined || content == null) return true;
    if (typeof content == 'string') {
        if (content == undefined || content == null || content.trim().length==0) return true;
        return false;
    }else if (typeof content == 'object') {
        if (content == undefined || content == null) return true;
        return false;
    }
}

// 检查号码状态
export const CheckPhoneState = {
  ONE: '1',
  TWO: '2',
  THREE: '3',
  FOUR:'4'
};

// 协议类型
export const ProtocolType = {
	/**隐私政策*/
	PRIVACY_POLICY:'1',
	/**用户协议*/
	USER_AGREEMENT: '2',
};